Skip to content

Extract every patch segment and decode byte lines - #78

Closed
Anurag-S1ngh wants to merge 1 commit into
aboutcode-org:mainfrom
Anurag-S1ngh:fix/57-patch-bytes
Closed

Anurag-S1ngh wants to merge 1 commit into
aboutcode-org:mainfrom
Anurag-S1ngh:fix/57-patch-bytes

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown

Summary

extractcode --all-formats libmediainfo-0.7.43.diff raised sequence item 0: expected str instance, bytes found. patch_info() yields whatever the patch library returns, and that library returns bytes lines, while extract() joins them as text. The same loop also returned after the first patch segment, so a multi-patch file only produced one extracted file.

Changes

  • Decode bytes lines from patch_text() with UTF-8 and fall back to Latin-1, then strip, so patch_info() always yields text lines.
  • Move return [] outside the loop in extract() so every patch segment is written.
  • Add two regression tests: a multi-segment patch file and the libmediainfo patch from the report.

Testing

  • pytest tests/test_patch.py: 199 passed, 2 xfailed.
  • Full suite: 77 failed, 441 passed, 33 skipped, 10 xfailed.
  • On unmodified main in the same environment: 83 failed, 433 passed, 33 skipped, 10 xfailed. The six extra fixes are the patch tests that were failing because of the same byte decoding. The remaining failures need the 7z and rar extraction plugins, which are not installed here.
  • ruff check and ruff format --check pass.
  • Manual check: dnsmasq_2.63-1.diff now writes 19 subfiles for 19 segments, and unionfs-2.5.1_for_2.6.23.17.diff writes 43 for 43.

Closes #57

patch.extract joined the lines from patch_info as text, but the patch library returns bytes, so extraction raised 'expected str instance, bytes found'. Decode byte lines as UTF-8 with a Latin-1 fallback and strip them in patch_info. Also move the return out of the loop so every patch segment is written, not just the first. Add regression tests for both cases.

Signed-off-by: Anurag Singh <anuragsingh2313@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error while extracting patch file

2 participants